package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.system.domain.SysArea;
import com.ruoyi.system.service.ISysAreaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 地区信息Controller
 * 
 * @author ruoyi
 * @date 2023-12-19
 */
@Slf4j
@RestController
@RequestMapping("/area")
public class SysAreaController extends BaseController
{
    @Autowired
    private ISysAreaService sysAreaService;

    /**
     * 查询地区信息列表
     */
    ////@RequiresPermissions("system:dict:list")
    @GetMapping("/list")
    public TableDataInfo list(SysArea sysArea)
    {
        startPage();
        List<SysArea> list = sysAreaService.selectSysAreaList(sysArea);
        return getDataTable(list);
    }

    /**
     * 查询省市区信息列表
     */
    ////@RequiresPermissions("system:dict:list")
    @GetMapping("/selectSysAreas")
    public AjaxResult selectSysAreas(SysArea sysArea)
    {
        log.info("查询省市区信息列表，param：{}", sysArea);
        return AjaxResult.success(sysAreaService.selectSysAreas(sysArea));
    }
    /**
     * 导出地区信息列表
     */
    ////@RequiresPermissions("system:area:export")
    @Log(title = "地区信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysArea sysArea)
    {
        List<SysArea> list = sysAreaService.selectSysAreaList(sysArea);
        ExcelUtil<SysArea> util = new ExcelUtil<SysArea>(SysArea.class);
        util.exportExcel(response, list, "地区信息数据");
    }

    /**
     * 获取地区信息详细信息
     */
    ////@RequiresPermissions("system:area:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysAreaService.selectSysAreaById(id));
    }


    @GetMapping(value = "/getAreaList")
    public AjaxResult getAreaList(@RequestParam("pid") Long pid)
    {
        return AjaxResult.success(sysAreaService.getAreaList(pid));
    }

    /**
     * 新增地区信息
     */
    ////@RequiresPermissions("system:area:add")
    @Log(title = "地区信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysArea sysArea)
    {
        return toAjax(sysAreaService.insertSysArea(sysArea));
    }

    /**
     * 修改地区信息
     */
    ////@RequiresPermissions("system:area:edit")
    @Log(title = "地区信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysArea sysArea)
    {
        return toAjax(sysAreaService.updateSysArea(sysArea));
    }

    /**
     * 删除地区信息
     */
    ////@RequiresPermissions("system:area:remove")
    @Log(title = "地区信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysAreaService.deleteSysAreaByIds(ids));
    }


}
